package com.sec.android.app.myfiles.widget.listview.listdecorator;

import android.content.Context;
import android.widget.AbsListView;

import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.log.SamsungAnalyticsLog;
import com.sec.android.app.myfiles.navigation.NavigationInfo;
import com.sec.android.app.myfiles.util.PreferenceUtils;
import com.sec.android.app.myfiles.widget.listview.AbsListViewImp;
import com.sec.android.app.myfiles.widget.listview.pinchview.PinchGridView;

/**
 * Created by jujube.lee on 2016-04-01.
 */
public abstract class AbsListDecorator {
    protected Context mContext;
    protected AbsListViewImp mAbsListView;
    protected AbsListView mListView;
    protected boolean mIsPinchEnabled = true;
    protected NavigationInfo mNavigationInfo;
    protected PinchGridView.OnLayoutAnimationListener mOnLayoutAnimationListener = new PinchGridView.OnLayoutAnimationListener() {

        @Override
        public void onAnimationStart(PinchGridView pinchGridView) {
        }

        @Override
        public void onAnimationEnd(PinchGridView pinchGridView) {
            if (mNavigationInfo != null) {
                AbsMyFilesFragment fragment = mNavigationInfo.getCurFragment();
                if (fragment != null) {
                    SamsungAnalyticsLog.sendLog(fragment.getProcessId(), pinchGridView.getSAEvent(), SamsungAnalyticsLog.SelectMode.NORMAL);
                }
            }

            int pinchDepth = ((PinchGridView) mListView).getPinchDepth();
            PreferenceUtils.setGridViewPinchDepth(mContext, pinchDepth);
        }
    };

    public void setListInfo(Context context, AbsListViewImp listView, NavigationInfo navigationInfo) {
        mContext = context;
        mAbsListView = listView;
        mListView = mAbsListView.getListView();
        mNavigationInfo = navigationInfo;
        ((PinchGridView) mListView).setOnLayoutAnimationListener(mOnLayoutAnimationListener);
    }

    public boolean isPinchEnabled() {
        return mIsPinchEnabled;
    }

    public void setPinchEnabled(boolean value) {
        mIsPinchEnabled = value;
    }

    public void disablePinchOperation() {
        ((PinchGridView) mListView).setEnablePinchOperation(false);
        setPinchEnabled(false);
    }

    public void enablePinchOperation() {
        ((PinchGridView) mListView).setEnablePinchOperation(true);
        setPinchEnabled(true);
    }

    public abstract void refreshLayout();

    public abstract int getListLayoutId();

    public abstract int getViewStubId();

    public abstract int getItemLayoutId();

    public abstract void stopPinchZoomWorking();
}
